package com.pgy.general.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pgy.general.entity.User;
import com.pgy.general.mapper.UserMapper;
import com.pgy.general.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Cc
 * @since 2021-01-26
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean saveUser(User user) {
        boolean save = saveOrUpdate(user);
        return save;
    }

    @Override
    public User queryByName(User user) {
        QueryWrapper<User> queryWrapper= Wrappers.<User> query();

        queryWrapper.eq("username",user.getUsername());
        User user1 = userMapper.selectOne(queryWrapper);
        return user1;
    }

    @Override
    public User queryById(String userId) {
        return getById(userId);
    }

    @Override
    public boolean deleteUser(int userId) {
        return removeById(userId);
    }

    @Override
    public Page<User> querusers(Integer currrntPage, Integer size, Integer townId, Integer villageId, String keywords, User userByToken) {
        QueryWrapper<User> queryWrapper= Wrappers.<User> query();
        queryWrapper.orderByDesc("createTime");
        Page<User> page =userMapper.selectPage(new Page<User>(currrntPage,size),queryWrapper);
        return page;
    }
}
